﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace msBsc.WebUi.ShpMana
{
    public partial class wfAddCertificate : msBsc.Cls.BPageHt
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        private void addCertificate()
        {
            //(string djackId, string certificateNumber, string certificatePicture, string name, string gender, string nationId, string nationName, string countryId, string countryName, string cityId, string cityName, string destinationId, string destinationName, string birthDate, string issueDate, string quasiType, string effStartDate, string endDate, string certificateType, string publisherId
            string djackId = this.GetParamHtValue("djackId");
            string certificateNumber = this.GetParamHtValue("certificateNumber");
            string certificatePicture = this.GetParamHtValue("certificatePicture");
            string name = this.GetParamHtValue("name");
            string gender = this.GetParamHtValue("gender");
            string nationId = this.GetParamHtValue("nationId");
            string nationName = this.GetParamHtValue("nationName");
            string countryId = this.GetParamHtValue("countryId");
            string countryName = this.GetParamHtValue("countryName");
            string cityId = this.GetParamHtValue("cityId");
            string cityName = this.GetParamHtValue("cityName");
            string destinationId = this.GetParamHtValue("destinationId");
            string destinationName = this.GetParamHtValue("destinationName");
            string birthDate = this.GetParamHtValue("birthDate");
            string issueDate = this.GetParamHtValue("issueDate");
            string quasiType = this.GetParamHtValue("quasiType");
            string effStartDate = this.GetParamHtValue("effStartDate");
            string endDate = this.GetParamHtValue("endDate");
            string certificateType = this.GetParamHtValue("certificateType");
            string publisherId = msBsc.SvRef.UserInfo.Operator;
            if (string.IsNullOrEmpty(publisherId))
            {
                this.ExecJScript("layer.alert('请登录！', 3);location.reload();");
            }
            if (string.IsNullOrEmpty(djackId) || string.IsNullOrEmpty(certificateNumber) || string.IsNullOrEmpty(certificatePicture) || string.IsNullOrEmpty(name) || string.IsNullOrEmpty(gender) || string.IsNullOrEmpty(nationId) || string.IsNullOrEmpty(nationName) || string.IsNullOrEmpty(countryId) || string.IsNullOrEmpty(countryName) || string.IsNullOrEmpty(cityId) || string.IsNullOrEmpty(cityName) || string.IsNullOrEmpty(destinationId) || string.IsNullOrEmpty(destinationName) || string.IsNullOrEmpty(birthDate) || string.IsNullOrEmpty(issueDate) || string.IsNullOrEmpty(quasiType) || string.IsNullOrEmpty(effStartDate) || string.IsNullOrEmpty(endDate) || string.IsNullOrEmpty(certificateType))
            {
                this.ExecJScript("layer.alert('请完善资格证信息！', 3);");
                return;
            }
            using (msBsc.AppLogic.DataAlc.CBizQualificationCertificate certificate = new AppLogic.DataAlc.CBizQualificationCertificate())
            {
                //drivingLicense.AddDrivingLicense();
                using (msBsc.AppLogic.DataAlc.CBizSysFile oCBizSysFile = new msBsc.AppLogic.DataAlc.CBizSysFile())
                {
                    //保存到系统永久目录，之前上传时存到临时目录的，也可另写代码拷贝文件到其他目录
                    certificatePicture = oCBizSysFile.SaveImgToServer(""
                        , msBsc.SvRef.UserInfo.Operator
                        , "1"
                        , "VEH"
                        , ""
                        , certificatePicture//文件来源虚拟路径
                        , ""//文件来源物理路径，虚拟和物理只有一个就行
                        , true);
                }
                string strRet = certificate.AddCertificate(djackId, certificateNumber, certificatePicture, name, gender, nationId, nationName, countryId, countryName, cityId, cityName, destinationId, destinationName, birthDate, issueDate, quasiType, effStartDate, endDate, certificateType, publisherId);// vehicleInfo.AddVehicle(djkId, vehicleName, buyTime, seats, price, serviceArea, vehicleType, vehicleBrand, vehicleColor, serviceType, picture, publisherId, vehicleNumber);
                if (strRet != "OK")
                {
                    this.ExecJScript("layer.alert('" + strRet + "', 3);");
                    return;
                }
                this.ExecJScript(@"success();");
            }
        }


        private void getArea2()
        {
            string parentsId = this.GetParamHtValue("parentsId");
            string cityId = "";
            string destionId = "";
            using (msBsc.AppLogic.DataAlc.CBizCountryCity cbcc = new AppLogic.DataAlc.CBizCountryCity())
            {
                DataSet ds = cbcc.SelectCountryByParentId(parentsId);
                if (ds == null || ds.Tables[0].Rows.Count < 0)
                {
                    return;
                }
                if (string.IsNullOrEmpty(cityId))
                {
                    cityId = ds.Tables[0].Rows[0]["COUNTRY_CITY_ID"].ToString();
                }
                string strJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 10000, "");
                this.ExecJScript(@"setCity(" + strJson + @",""selCity"",'" + cityId + "');");

                ds = cbcc.SelectCountryByParentId(cityId);
                if (ds == null || ds.Tables[0].Rows.Count < 0)
                {
                    return;
                }
                DataRow dr = ds.Tables[0].NewRow();
                dr["COUNTRY_CITY_ID"] = "";
                dr["COUNTRY_CITY_NME"] = "请选择";
                ds.Tables[0].Rows.InsertAt(dr, 0);
                if (string.IsNullOrEmpty(destionId))
                {
                    destionId = ds.Tables[0].Rows[0]["COUNTRY_CITY_ID"].ToString();
                }
                strJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 10000, "");
                this.ExecJScript(@"setCity(" + strJson + @",""selDestination"",'" + destionId + "');");
            }
        }
        private void getArea3()
        {
            string parentsId = this.GetParamHtValue("parentsId");
            string destionId = "";
            using (msBsc.AppLogic.DataAlc.CBizCountryCity cbcc = new AppLogic.DataAlc.CBizCountryCity())
            {
                DataSet ds = cbcc.SelectCountryByParentId(parentsId);
                if (ds == null || ds.Tables[0].Rows.Count < 0)
                {
                    return;
                }
                DataRow dr = ds.Tables[0].NewRow();
                dr["COUNTRY_CITY_ID"] = "";
                dr["COUNTRY_CITY_NME"] = "请选择";
                ds.Tables[0].Rows.InsertAt(dr, 0);
                if (string.IsNullOrEmpty(destionId))
                {
                    destionId = ds.Tables[0].Rows[0]["COUNTRY_CITY_ID"].ToString();
                }
                string strJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 10000, "");
                this.ExecJScript(@"setCity(" + strJson + @",""selDestination"",'" + destionId + "');");
            }
        }

        public override void DoAction()
        {
            if (this.strAction == "init")
            {
                getArea2();
            }
            else if (this.strAction == "addCertificate")
            {
                addCertificate();
            }
            else if (this.strAction == "upCountry")
            {
                getArea2();
            }
            else if (this.strAction == "upCity")
            {
                getArea3();
            }
        }
    }
}